/*
* @Author: dengjiayao
* @Date:   2018-03-21 10:13:29
* @Last Modified by:   dengjiayao
* @Last Modified time: 2018-03-21 13:26:19
*/
import { modal } from 'vue-strap'
import { showMsg, configSubaccount } from '../../vuex/action'

export default {
  name: 'child-account-config',
  data() {
    return {
      showModal: false,
      actionType: 'ADD',
      form: {
        brokerageCusCode: '',
        customerName: '',
        receiveBankaccount: ''
      }
    }
  },
  components: {
    'vue-modal': modal
  },
  vuex: {
    actions: {
      xShowMsg: showMsg,
      xAdd: configSubaccount
    }
  },
  methods: {
    valid() {
      let fields = ['brokerageCusCode', 'customerName', 'receiveBankaccount']
      for (let k of fields) {
        let v = this.form[k] + ''
        if (v.length === 0) {
          return Promise.reject({
            error_msg: '*标识的均为必填项'
          })
        }
      }
      return Promise.resolve()
    },
    submit() {
      this.valid()
        .then(() => {
          return this.xAdd(this.form)
        })
        .then(() => {
          this.showModal = false
        })
        .catch(res => {
          this.xShowMsg({
            type: 'danger',
            content: res.error_msg
          })
        })
    }
  }
}
